package cn.demoxy.controller;

import cn.demoxy.annotation.Log;
import cn.demoxy.enums.BusinessTypeEnum;
import cn.demoxy.model.dto.DemoTableDTO;
import cn.demoxy.result.R;
import cn.demoxy.service.IDemoTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;

/**
 * @auther demo
 * @date 2022/6/2 11:40
 * 数据源表控制层
 */
@Api(tags =" 数据源表接口信息 ")
@AllArgsConstructor
@RestController
@RequestMapping("/admin/demo-table")
@CrossOrigin
public class DemoTableController {

    /**
     * 数据源表service
     */
    private IDemoTableService demoTableService;

    /**
     * 根据数据库查询所有的表
     * @param tableDTO
     * @return
     */
    @ApiOperation(value = "根据数据库查询所有的表")
    @PostMapping("/selectAllTablesByDataBase")
    @RequiresPermissions("demo-table:selectAllTablesByDataBase")
    public R selectAllTablesByDataBase(@RequestBody DemoTableDTO tableDTO) throws SQLException {
        return R.ok(demoTableService.selectAllTablesByDataBase(tableDTO));
    }

    @ApiOperation(value = "代码生成")
    @GetMapping("/codeGenerator")
//    @Log(title = "代码生成",businessType = BusinessTypeEnum.GENCODE)
//    @RequiresPermissions("demo-table:codeGen")
    public void codeGenerator(DemoTableDTO tableDTO) throws FileNotFoundException, UnsupportedEncodingException {
        demoTableService.codeGenerator(tableDTO);
    }


}
